﻿package com.victim.snake.graphics.createRoomClass.controls{
	import fl.controls.ComboBox;
	import flash.events.Event;
	import flash.display.LoaderInfo;
	import flash.display.Bitmap;
	import com.victim.snake.util.Loader;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	import com.victim.snake.graphics.createRoomClass.style.CellRenderer;


	//ComboBoxUpSkin皮肤
	public class ComboBox extends fl.controls.ComboBox{
		
		static private var UpSkin:Bitmap=null;
		static private var OverSkin:Bitmap=null;
		static private var DownSkin:Bitmap=null;
		static private var UpSkinState:uint=0;	//0末下载,1下载中,2以下载
		static private var OverSkinState:uint=0;	//0末下载,1下载中,2以下载
		static private var DownSkinState:uint=0;	//0末下载,1下载中,2以下载
		
		
		//构造函数
		public function ComboBox() {			
			this.addEventListener(ComboBoxEvent.UpSkinIsLoad,setUpSkin);	//监听upSkin下载
			this.addEventListener(ComboBoxEvent.OverSkinIsLoad,setOverSkin);	//监听overSkin下载
			this.addEventListener(ComboBoxEvent.DownSkinIsLoad,setDownSkin);	//监听downSkin下载
			this.loadUpSkin();	//开始下载upSkin
			this.loadOverSkin();	//开始下载overSkin
			this.loadDownSkin();	//开始下载downSkin
			this.setStyle("textPadding",-2);
			var tf:TextFormat=new TextFormat();			
			tf.size=12;			
			tf.leftMargin=6;
			this.textField.setStyle("textFormat",tf);
			
			this.dropdown.rowHeight=16;	//设置下拉列表的行高
			this.dropdown.setStyle("cellRenderer",CellRenderer);	//设置下拉框单元格样式
			
		}		
		
		//开始下载upSkin
		private function loadUpSkin():void{
			if(com.victim.snake.graphics.createRoomClass.controls.ComboBox.UpSkinState==0 || com.victim.snake.graphics.createRoomClass.controls.ComboBox.UpSkinState==1){
				com.victim.snake.graphics.createRoomClass.controls.ComboBox.UpSkinState=1;
				new Loader("image/main/createRoom/comboBoxUpSkin.png",loadUpSkinEvent);
			}else{
				var comboxEvent:ComboBoxEvent=new ComboBoxEvent(ComboBoxEvent.UpSkinIsLoad);
				this.dispatchEvent(comboxEvent);
			}
		}		
		//当upSkin图片下载完成时调用的方法
		private function loadUpSkinEvent(e:Event):void{			
			var loaderInfo:LoaderInfo=LoaderInfo(e.target);
			com.victim.snake.graphics.createRoomClass.controls.ComboBox.UpSkin=Bitmap(loaderInfo.content);
			var comboxEvent:ComboBoxEvent=new ComboBoxEvent(ComboBoxEvent.UpSkinIsLoad);
			this.dispatchEvent(comboxEvent);
			com.victim.snake.graphics.createRoomClass.controls.ComboBox.UpSkinState=2;
		}
		//设置控件的upSkin样式
		private function setUpSkin(e:Event):void{
			this.setStyle("upSkin",com.victim.snake.graphics.createRoomClass.controls.ComboBox.UpSkin);
		}
		
		//开始下载overSkin
		private function loadOverSkin():void{
			if(com.victim.snake.graphics.createRoomClass.controls.ComboBox.OverSkinState==0 || com.victim.snake.graphics.createRoomClass.controls.ComboBox.OverSkinState==1){
				com.victim.snake.graphics.createRoomClass.controls.ComboBox.OverSkinState=1;
				new Loader("image/main/createRoom/comboBoxOverSkin.png",loadOverSkinEvent);
			}else{
				var comboxEvent:ComboBoxEvent=new ComboBoxEvent(ComboBoxEvent.OverSkinIsLoad);
				this.dispatchEvent(comboxEvent);
			}
		}		
		//当overSkin图片下载完成时调用的方法
		private function loadOverSkinEvent(e:Event):void{			
			var loaderInfo:LoaderInfo=LoaderInfo(e.target);
			com.victim.snake.graphics.createRoomClass.controls.ComboBox.OverSkin=Bitmap(loaderInfo.content);
			var comboxEvent:ComboBoxEvent=new ComboBoxEvent(ComboBoxEvent.OverSkinIsLoad);
			this.dispatchEvent(comboxEvent);
			com.victim.snake.graphics.createRoomClass.controls.ComboBox.OverSkinState=2;
		}		
		//设置控件的overSkin样式
		private function setOverSkin(e:Event):void{
			this.setStyle("overSkin",com.victim.snake.graphics.createRoomClass.controls.ComboBox.OverSkin);
		}
		
		//开始下载downSkin
		private function loadDownSkin():void{
			if(com.victim.snake.graphics.createRoomClass.controls.ComboBox.DownSkinState==0 || com.victim.snake.graphics.createRoomClass.controls.ComboBox.DownSkinState==1){
				com.victim.snake.graphics.createRoomClass.controls.ComboBox.DownSkinState=1;
				new Loader("image/main/createRoom/comboBoxDownSkin.png",loadDownSkinEvent);
			}else{
				var comboxEvent:ComboBoxEvent=new ComboBoxEvent(ComboBoxEvent.DownSkinIsLoad);
				this.dispatchEvent(comboxEvent);
			}
		}		
		//当downSkin图片下载完成时调用的方法
		private function loadDownSkinEvent(e:Event):void{			
			var loaderInfo:LoaderInfo=LoaderInfo(e.target);
			com.victim.snake.graphics.createRoomClass.controls.ComboBox.DownSkin=Bitmap(loaderInfo.content);
			var comboxEvent:ComboBoxEvent=new ComboBoxEvent(ComboBoxEvent.DownSkinIsLoad);
			this.dispatchEvent(comboxEvent);
			com.victim.snake.graphics.createRoomClass.controls.ComboBox.DownSkinState=2;
		}		
		//设置控件的downSkin样式
		private function setDownSkin(e:Event):void{
			this.setStyle("downSkin",com.victim.snake.graphics.createRoomClass.controls.ComboBox.DownSkin);
		}
	}
	
}
